﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace Erebos.ConnectionLostScreenFiles
{
    class ConnectionLostScreen : Screen
    {
        private string _text;

        public ConnectionLostScreen()
        {
            _text = "Verbindung zum Erebos-Server wurde verloren." + Environment.NewLine + "Drücke ESC um Erebos zu beenden.";
        }

        public override void Update(GameTime gameTime)
        {
            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
                MainGame.Close = true;
            base.Update(gameTime);
        }

        public override void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            float scale = 1.2f;
            Vector2 textSize = MainGame.Fonts["Arial24Bold"].MeasureString(_text) * scale;
            if (textSize.X > ScreenSizeHelper.SizeWidth || textSize.Y > ScreenSizeHelper.SizeHeight)
            {
                textSize = MainGame.Fonts["Arial24Bold"].MeasureString(_text);
                scale = 1.0f;
            }

            int i = 0;
            foreach (string s in _text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None))
            {
                Vector2 txtSize = MainGame.Fonts["Arial24Bold"].MeasureString(s) * scale;
                Vector2 pos = new Vector2(ScreenSizeHelper.SizeWidth / 2 - txtSize.X / 2, ScreenSizeHelper.SizeHeight / 2 - textSize.Y / 2 + (i * 32 * scale));
                spriteBatch.DrawString(MainGame.Fonts["Arial24Bold"], s, pos, Color.White, 0.0f, new Vector2(0, 0), scale, SpriteEffects.None, 0);
                i++;
            }
        }
    }
}
